package com.ruoyi.combat.service.useralignment.impl;

import java.util.*;

import com.ruoyi.combat.domain.useralignment.CombatUserWb;
import com.ruoyi.combat.domain.userlocation.CombatBlog;
import com.ruoyi.combat.domain.userlocation.CombatUser;
import com.ruoyi.combat.mapper.useralignment.CombatUserWbMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.combat.mapper.useralignment.CombatBlogWbMapper;
import com.ruoyi.combat.domain.useralignment.CombatBlogWb;
import com.ruoyi.combat.service.useralignment.ICombatBlogWbService;

/**
 * 课题五微博用户发布内容Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-12
 */
@Service
public class CombatBlogWbServiceImpl implements ICombatBlogWbService {
    @Autowired
    private CombatBlogWbMapper combatBlogWbMapper;
    @Autowired
    private CombatUserWbMapper combatUserWbMapper;

    /**
     * 查询课题五微博用户发布内容
     *
     * @param id 课题五微博用户发布内容主键
     * @return 课题五微博用户发布内容
     */
    @Override
    public CombatBlogWb selectCombatBlogWbById(Long id) {
        return combatBlogWbMapper.selectCombatBlogWbById(id);
    }

    /**
     * 查询课题五微博用户发布内容列表
     *
     * @param combatBlogWb 课题五微博用户发布内容
     * @return 课题五微博用户发布内容
     */
    @Override
    public List<CombatBlogWb> selectCombatBlogWbList(CombatBlogWb combatBlogWb) {
        List<CombatBlogWb> combatBlogWbs = combatBlogWbMapper.selectCombatBlogWbList(combatBlogWb);
        for (CombatBlogWb blog : combatBlogWbs) {
            String reportImages = blog.getReportImages();
            if (StringUtils.isNotEmpty(reportImages) && !reportImages.contains("combat")) {
                String[] split = reportImages.split(",");
                String path = "";
                Date reportime = blog.getReportime();
                String data = DateUtils.parseDateToStr("yyyyMMdd", reportime);
                for (int i = 0; i < split.length; i++) {
                    int n = i + 1;
                    if (StringUtils.isNotEmpty(path)) {
                        path = path + ",/combat/" + data + " _" + blog.getId() + "_" + n + ".jpg";
                    } else {
                        path = "/combat/" + data + " _" + blog.getId() + "_" + n + ".jpg";
                    }
                    if (split.length == 1) {
                        path = "/combat/" + data + " _" + blog.getId() + ".jpg";
                    }
                }
                blog.setReportImages(path);
            }
        }
        return combatBlogWbs;
    }

    /**
     * 新增课题五微博用户发布内容
     *
     * @param combatBlogWb 课题五微博用户发布内容
     * @return 结果
     */
    @Override
    public int insertCombatBlogWb(CombatBlogWb combatBlogWb) {
        return combatBlogWbMapper.insertCombatBlogWb(combatBlogWb);
    }

    /**
     * 修改课题五微博用户发布内容
     *
     * @param combatBlogWb 课题五微博用户发布内容
     * @return 结果
     */
    @Override
    public int updateCombatBlogWb(CombatBlogWb combatBlogWb) {
        return combatBlogWbMapper.updateCombatBlogWb(combatBlogWb);
    }

    /**
     * 批量删除课题五微博用户发布内容
     *
     * @param ids 需要删除的课题五微博用户发布内容主键
     * @return 结果
     */
    @Override
    public int deleteCombatBlogWbByIds(Long[] ids) {
        return combatBlogWbMapper.deleteCombatBlogWbByIds(ids);
    }

    /**
     * 删除课题五微博用户发布内容信息
     *
     * @param id 课题五微博用户发布内容主键
     * @return 结果
     */
    @Override
    public int deleteCombatBlogWbById(Long id) {
        return combatBlogWbMapper.deleteCombatBlogWbById(id);
    }

    @Override
    public Map postingTrends(Long id) {
        return Collections.emptyMap();
    }

    @Override
    public List<Map> sendStatistics(String userId) {
        return combatBlogWbMapper.sendStatistics(userId);
    }

    @Override
    public Map numberStatistics(String userId) {
        CombatBlogWb combatBlog = new CombatBlogWb();
        combatBlog.setUserId(userId);
        List<CombatBlogWb> combatBlogs = combatBlogWbMapper.selectCombatBlogWbList(combatBlog);
        CombatUserWb combatUser = combatUserWbMapper.selectCombatUserWbByUserId(userId);
        Map<String, Long> result = new HashMap<>();
        result.put("userFansNum", combatUser.getUserFansNum());
        result.put("userFocusNum", combatUser.getUserFocusNum());
        result.put("userBlogNum", (long) combatBlogs.size());
        return result;
    }
}
